<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="chrome=1" />
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
  </head>
  <body>
    <div>onbeforeunload事件绑定</div>

    <script type="text/javascript">
      //适用于IE和FF，不区分刷新和关闭，最简单的
      window.onbeforeunload = onclose;
      function onclose() {
        localStorage.setItem("onclose", new Date().getTime());
        console.log(11111111111);
      }

      document.writeln(
        "localStorage下取到的:" + localStorage.getItem("onclose")
      );
    </script>
  </body>
</html>
